package com.aboo.dao.callback;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.aboo.po.BasePO;

public class UpdateCallbackHandler implements HibernateCallback {

	private static Logger log = Logger.getLogger(DeleteCallbackHandler.class);
	private List<BasePO> list;
	private Class<BasePO> clazz;
	
	public UpdateCallbackHandler(List<BasePO> list, Class<BasePO> clazz) {
		if (list == null) {
			this.list = new ArrayList<BasePO>();
		} else {
			this.list = list;
		}
		this.clazz = clazz;
	}
	
	public Object doInHibernate(Session s) throws HibernateException,
			SQLException {
		BasePO oper = null;
		for (Iterator<BasePO> iter = list.iterator(); iter.hasNext();) {
			oper = iter.next();			
			if (oper != null) {
				s.update(oper);
			} else {
				log.error("Can't not find the object to be update! id: " + oper.getId());
			}
		}
		return null;
	}

}
